// 页面添加水印效果
const setWatermark = (element, str) => {
    const id = 'watermark-123412416'; // 修改 id 的命名方式
    if (element.querySelector(`#${id}`) !== null) element.removeChild(element.querySelector(`#${id}`));
    const can = document.createElement('canvas');
    can.width = 250;
    can.height = 150;
    const cans = can.getContext('2d');
    cans.rotate((-20 * Math.PI) / 180);
    cans.font = '12px Vedana';
    cans.fillStyle = 'rgba(200, 200, 200, 0.30)';
    cans.textBaseline = 'middle';
    cans.fillText(str, can.width / 10, can.height / 2);
    const div = document.createElement('div');
    div.id = id;
    div.style.pointerEvents = 'none';
    div.style.top = '0px';
    div.style.left = '0px';
    div.style.zIndex = '10000';
    div.style.position = 'absolute'; // 修改为 absolute 定位
    div.style.width = `${element.clientWidth}px`;
    div.style.height = `${element.clientHeight}px`;
    div.style.background = `url(${can.toDataURL('image/png')}) left top repeat`;
    element.appendChild(div);
    return id;
  };
 
  const watermark1 = {
    set: (element, str) => {
      let id = setWatermark(element, str);
      if (element.querySelector(`#${id}`) === null) id = setWatermark(element, str);
    },
    del: (element) => {
        console.log('element',element)
        const id = 'watermark-123412416'; // 修改 id 的命名方式
        if (element.querySelector(`#${id}`) !== null) element.removeChild(element.querySelector(`#${id}`));
    },
  };
  
// 导出方法
export default watermark1;
